class Solution(object):
    def searchMatrix(self, matrix, target):
        """
        :type matrix: List[List[int]]
        :type target: int
        :rtype: bool
        """
        result = False
        for l in matrix:
            if target > l[-1]:
                continue
            i, j = 0, len(l)-1
            while i <= j:
                m = int((i+j)/2)
                if l[m] == target:
                    result = True
                    break
                if l[m] < target:
                    i = m + 1
                else:
                    j = m - 1
            break
        return result
